package com.ipat.model;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;

public final class Patent implements Serializable {

	private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
	private static final long serialVersionUID = 1L;
	private String title;
	private String pubNum;
	private Date pubDate;
	private List<String> inventors;
	private List<String> applicants;
	private List<String> intlClassification;
	private String europClassification;
	private String appNum;
	private Date appDate;
	private Map<String, Date> priorityNum;
	private List<String> citedDoc;
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	public String getPubNum() {
		return pubNum;
	}
	public void setPubNum(String pubNum) {
		this.pubNum = pubNum;
	}
	public Date getPubDate() {
		if(this.pubDate != null) {
			return new Date(this.pubDate.getTime());
		}
		return null;
	}
	public void setPubDate(Date pubDate) {
		if(pubDate != null) {
			this.pubDate = new Date(pubDate.getTime());
		}
		else {
			this.pubDate = null;
		}
	}
	public List<String> getInventors() {
		if(this.inventors != null) {
			return new ArrayList<String>(this.inventors);
		}
		else {
			return new ArrayList<String>();
		}
	}
	public void setInventors(List<String> inventors) {
		if(inventors != null) {
			this.inventors = new ArrayList<String>(inventors);
		}
		else {
			this.inventors = new ArrayList<String>();
		}
	}
	public List<String> getApplicants() {
		if(this.applicants != null) {
			return new ArrayList<String>(this.applicants);
		}
		else {
			return new ArrayList<String>();
		}
	}
	public void setApplicants(List<String> applicants) {
		if(applicants != null) {
			this.applicants = new ArrayList<String>(applicants);
		}
		else {
			this.applicants = new ArrayList<String>();
		}
	}
	public List<String> getIntlClassification() {
		if(this.intlClassification != null) {
			return new ArrayList<String>(this.intlClassification);
		}
		else {
			return new ArrayList<String>();
		}
	}
	public void setIntlClassification(List<String> intlClassification) {
		if(intlClassification != null) {
			this.intlClassification = new ArrayList<String>(intlClassification);
		}
		else {
			this.intlClassification = new ArrayList<String>();
		}
	}
	public String getEuropClassification() {
		return europClassification;
	}
	public void setEuropClassification(String europClassification) {
		this.europClassification = europClassification;
	}
	public String getAppNum() {
		return appNum;
	}
	public void setAppNum(String appNum) {
		this.appNum = appNum;
	}
	public Date getAppDate() {
		if(this.appDate != null) {
			return new Date(appDate.getTime());
		}
		return null;
		
	}
	public void setAppDate(Date appDate) {
		if(appDate != null) {
			this.appDate = new Date(appDate.getTime());
		}
		else {
			this.appDate = null;
		}
	}
	public Map<String, Date> getPriorityNum() {
		
		if(this.priorityNum != null) {
			return new HashMap<String, Date>(this.priorityNum);
		}
		
		return new HashMap<String, Date>();
	}
	public void setPriorityNum(Map<String, Date> priorityNum) {
		if(priorityNum != null) {
			this.priorityNum = new HashMap<String, Date>(priorityNum);
		}
		else {
			this.priorityNum = new HashMap<String, Date>();
		}
	}
	public List<String> getCitedDoc() {
		
		if(this.citedDoc != null) {
			return new ArrayList<String>(this.citedDoc);
		}
		else {
			return new ArrayList<String>();
		}
	}
	public void setCitedDoc(List<String> citedDoc) {
		if(citedDoc != null) {
			this.citedDoc = new ArrayList<String>(citedDoc);
		}
		else {
			this.citedDoc = new ArrayList<String>();
		}
	}
	
	public String toString() {
		StringBuffer sb = new StringBuffer();
		
		sb.append("title: " + this.getTitle() + "\n");
		sb.append("publication number: " + this.getPubNum() + "\n");
		sb.append("publication date: " + sdf.format(this.getPubDate()) + "\n");
		if(this.inventors != null) {
			sb.append("inventors: ");
			for(String inventor : this.inventors) {
				sb.append(inventor + "; ");
			}
			sb.append("\n");
		}
		if(this.applicants != null) {
			sb.append("applicants: ");
			for(String applicant : this.applicants) {
				sb.append(applicant + "; ");
			}
			sb.append("\n");
		}
		if(this.europClassification != null) {
			sb.append("EC: " + this.getEuropClassification() + "\n");
		}
		if(this.intlClassification != null) {
			sb.append("IPC: ");
			for(String ipc : this.intlClassification) {
				sb.append(ipc + "; ");
			}
			sb.append("\n");
		}
		if(this.priorityNum != null) {
			sb.append("Publication info: ");
			Set<Entry<String, Date>> entrySet = this.priorityNum.entrySet();
			for(Entry<String, Date> entry : entrySet) {
				sb.append(entry.getKey() + "<>" + sdf.format(entry.getValue()) + "; ");
			}
			sb.append("\n");
		}
		return sb.toString();
	}
	
	
	
}
